package com.hljcert.data.service.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hljcert.data.service.common.result.Result;
import com.hljcert.data.service.system.dto.SysRoleDTO;
import com.hljcert.data.service.system.dto.SysRoleQueryDTO;
import com.hljcert.data.service.system.entity.SysRole;
import com.hljcert.data.service.system.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/sys/role")
@Slf4j
@Api("角色管理")
public class SysRoleController {

	@Autowired
	private SysRoleService sysRoleService;

	/**
	  * 分页列表查询
	 */
	@ApiOperation(value = "分页查询", httpMethod = "GET")
	@GetMapping(value = "/list")
	public Result<IPage<SysRole>> queryPageList(@ModelAttribute SysRoleQueryDTO params) {
		return Result.OK(this.sysRoleService.getPageList(params));
	}
	
	/**
	 * 添加
	 * @param role
	 * @return
	 */
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody SysRoleDTO role) {
		this.sysRoleService.add(role);
		return Result.OK();
	}
	
	/**
	 * 编辑
	 */
	@PutMapping(value = "/update")
	public Result<String> update(@RequestBody SysRoleDTO role) {
		this.sysRoleService.update(role);
		return Result.OK();
	}
	
	/**
	 * 通过id删除
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id") String id) {
		sysRoleService.delete(id);
		return Result.OK("删除角色成功");
	}

	/**
	 * 通过id查询
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/details")
	public Result<SysRole> details(@RequestParam(name="id",required=true) String id) {
		return Result.OK(this.sysRoleService.getById(id));
	}
}
